What does the program print to the monitor?

A good answer might be:

The variable contains: 123

Assignment Statement Syntax

This program printed out the same thing as the first example program. However, this program did not initialize the variable and so had to put a value into it later.

The syntax of assignment statements is easy. Assignment statements look like this:

variableName  =  expression ;

An assignment statement asks for the computer to perform two steps, in order:

  1. Evaluate the expression (that is: calculate a value.)
  2. Store the value in the variable.

For example, the assignment statement:

sum = 32 + 8 ;

asks for two actions:

  1. Evaluate the Expression — 32 + 8 is calculated, yielding 40.
  2. Store the value in the variable. — 40 is placed in sum

(May, 2002) Note: I've just spent six or so hours grading student programs from second semester computer science. Several programs were poorly written (and sometimes not working) because their authors forgot about these two steps of an assignment statement. Without this concept, an easy problem became difficult. Sometimes you really need to know this.

QUESTION 11:

What does the following assignment statement statement do:

sum = 42 - 12 ;